package peer.p2pnet;

import java.util.HashMap;

import peer.ThreadCounter;
import peer.tools.Mdb;


public class RemoveThread_CleanExit implements Runnable{
	Thread t;
	CastPubThread ct;
	public boolean run=true;
	Mdb mdb;
	int sourceSessionId;
	HashMap<DBNodeIdent, DBNode> castMemberTable;
	public RemoveThread_CleanExit(Mdb mdb,int sourceSessionId){
		this.mdb=mdb;
		this.sourceSessionId=sourceSessionId;
		castMemberTable=new HashMap<DBNodeIdent, DBNode>();
		t=new Thread(this);
		t.start();
	}
	
	public void stopAddThread(){
		run=false;
		t.interrupt();
	}
	
	@SuppressWarnings("unchecked")
	public void run() {
		
		String tstr="n4675jdr";
		peer.ThreadCounter tc;
		if(!peer.Config.ThreadStrTable.containsKey(tstr)){
			tc=new peer.ThreadCounter();
			peer.Config.ThreadStrTable.put(tstr, tc);
		}
		tc=(ThreadCounter) peer.Config.ThreadStrTable.get(tstr);
		tc.conut++;
		
		HashMap<DBNodeIdent, DBNode> dbBNodeList=peer.Config.loadDBNodeList(mdb,false);
		if(dbBNodeList.size()!=0){
			new CastRemoveThread(mdb,dbBNodeList,sourceSessionId);
		}
		peer.Config.assistServer.cleanTaskComplete(mdb, sourceSessionId);
		
		tc.conut--;
	}

}
